﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Commerce.CSK.Web.Controls
{
    public partial class CreditCardInfo : PaymentMethodControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override Commerce.Data.PaymentMethod CurrentPaymentMethod
        {
            get
            {
                return GetCard(); 
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private void SetCard(Commerce.Data.CreditCard card)
        {
            NameOnCard.Text = card.Name;
            CreditCardType.SelectedValue = card.CardType;
            AccountNumber.Text = card.MaskedNumber;
            ExpireMonth.Text = card.ExpirationMonth.ToString();
            ExpireYear.Text = card.ExpirationYear.ToString(); 
        }

        private Commerce.Data.CreditCard GetCard()
        {
            Commerce.Data.CreditCard cc = new Commerce.Data.CreditCard(
                CreditCardType.SelectedValue.ToString(), NameOnCard.Text,
                AccountNumber.Text, int.Parse(ExpireMonth.Text),
                int.Parse(ExpireYear.Text), CVV.Text);
            return cc; 


        }
    }
}